<template>
  <div class="all">
    <div class="header">
      <div class="left">强盛酒店</div>
      <div class="right">
        <router-link to="/Home" class="link">首页</router-link>
        <router-link to="/room" class="link">客房信息</router-link>
        <router-link to="/restaurant" class="link">酒店餐饮</router-link>
        <router-link to="/register" class="link" v-show="!isLogin">注册</router-link>
        <router-link to="/login" class="link" v-show="!isLogin">登录</router-link>
        <!--                <div class="contact" v-show="isLogin">-->
        <!--                    <span v-model="username" style="font-size: 14px">{{username}},欢迎您</span>-->
        <!--                </div>-->
        <router-link to="/person" class="link" v-show="isLogin" style="font-size: 22px;" >个人中心</router-link>
        <a href="javascript:;" to="/login" class="link" v-show="isLogin" @click="exit()"
           style="font-size: 22px">退出</a>
      </div>
    </div>
  </div>
</template>

<script>
import {get, getInfo, removeToken, getToken} from "@/utils/request";
import change from "@/utils/change";

export default {
  data() {
    return {
      isLogin: false,
      username: ""
    };
  },
  mounted() {
    change.$on('change', (flag) => {
      if (flag) {
        this.getUser()
      }
    });

  },
  methods: {
    // 跳转注册
    goRegister() {
      // 跳转页面
      this.$router.push({path: '/register'})
    },
    //  跳转登录
    goLogin() {
      // 跳转页面
      this.$router.push({path: '/login'})
    },
    exit() {
      this.isLogin = false;
      this.$router.push({path: '/login'});
      removeToken();
    },
    getUser() {
      // getToken();
      let a = undefined;
      if (a !== getToken()) {
        getInfo().then(res => {
          if (res.code === 200) {
            this.isLogin = true;
            this.username = res.user.nickName
          }
        });
      }
    }
  },
  created() {
    this.getUser()
  }
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

.all {
  width: 1400px;
  height: 80px;
  margin: 0 auto;
}

.all .header {
  display: flex;
  padding-top: 20px;
}

.header .left {
  width: 20%;
  font-size: 30px;
  margin-left: 30px;
  color: #4ab344;
}

.header .right {
  width: 100%;
  display: flex;
  justify-content: center;
}

.header .right .link {
  flex: 0.5;
  font-size: 22px;
  padding-top: 10px;
  text-decoration: none;
  color: #000;
}

.header .right .link:hover {
  flex: 0.5;
  font-size: 20px;
  padding-top: 10px;
  text-decoration: none;
  color: #4ab344;
}

.header .right div {
  flex: 1;
  font-size: 22px;
  padding-top: 10px;
}

.header .right div:hover {
  flex: 1;
  font-size: 22px;
  padding-top: 10px;
  color: #4ab344;
}

.router-link-active {
  font-weight: bold;
  color: white;
}
</style>
